<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
    
      <el-form-item label="大类" prop="bigCategory">
        <el-input
          v-model="queryParams.bigCategory"
          placeholder="请输入大类"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="小类" prop="smallCategory">
        <el-input
          v-model="queryParams.smallCategory"
          placeholder="请输入小类"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品种" prop="variety">
        <el-input
          v-model="queryParams.variety"
          placeholder="请输入品种"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    
      <el-form-item label="单价" prop="unitPrice">
        <el-input
          v-model="queryParams.unitPrice"
          placeholder="请输入单价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
      <el-form-item label="联系人" prop="linkMan">
        <el-input
          v-model="queryParams.linkMan"
          placeholder="请输入联系人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
     
     
     
      <el-form-item label="审核状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择审核状态">
          <el-option
            v-for="item in authState"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          >
          </el-option>
        </el-select>
      </el-form-item>
    
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['internet:intFoodMachinery:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['internet:intFoodMachinery:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['internet:intFoodMachinery:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['internet:intFoodMachinery:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="intFoodMachineryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="标题" show-overflow-tooltip align="center" prop="title" />
      <el-table-column label="大类" align="center" prop="bigCategory" />
      <el-table-column label="小类" align="center" prop="smallCategory" />
      <el-table-column label="品种" align="center" prop="variety" />
      <el-table-column label="产地" align="center" prop="producingArea" />
      <el-table-column label="可交易总量(个)" align="center" prop="tradableTotal" />
      <el-table-column label="单价" align="center" prop="unitPrice" />
      <el-table-column label="年份" align="center" prop="yearDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.yearDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="联系人" align="center" prop="linkMan" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="发布失效日期" align="center" prop="expirationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expirationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品图" align="center" prop="goodsPicArray" >
         <template slot-scope="scope">
          <img
            :src="scope.row.goodsPicArray"
            alt
            style="width: 80px; height: 80px; object-fit: cover"
          /> </template
        ><strong />
      </el-table-column>
      <el-table-column label="发布商" align="center" prop="expirationName" />
      <el-table-column label="审核状态" align="center" prop="stateNew" />
      <el-table-column label="操作"  width="200"
        fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['internet:intFoodMachinery:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
             v-if="scope.row.stateNew === '审核中'"
            icon="el-icon-delete"
            @click="handle(scope.row)"
            v-hasPermi="['internet:intFoodMachinery:remove']"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改食品机械对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标题" prop="title">
          <el-input  :disabled="delFlag" v-model="form.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="大类" prop="bigCategory">
          <el-input  :disabled="delFlag" v-model="form.bigCategory" placeholder="请输入大类" />
        </el-form-item>
        <el-form-item label="小类" prop="smallCategory">
          <el-input  :disabled="delFlag" v-model="form.smallCategory" placeholder="请输入小类" />
        </el-form-item>
        <el-form-item label="品种" prop="variety">
          <el-input  :disabled="delFlag" v-model="form.variety" placeholder="请输入品种" />
        </el-form-item>
        <el-form-item label="产地" prop="producingArea">
          <el-input  :disabled="delFlag" v-model="form.producingArea" placeholder="请输入产地" />
        </el-form-item>
        <el-form-item label="可交易总量(个)" prop="tradableTotal">
          <el-input  :disabled="delFlag" v-model="form.tradableTotal" placeholder="请输入可交易总量(个)" />
        </el-form-item>
        <el-form-item label="单价" prop="unitPrice">
          <el-input  :disabled="delFlag" v-model="form.unitPrice" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="年份" prop="yearDate">
          <el-date-picker clearable size="small"
            v-model="form.yearDate"
             :disabled="delFlag"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择年份">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="联系人" prop="linkMan">
          <el-input  :disabled="delFlag" v-model="form.linkMan" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input  :disabled="delFlag" v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="发布失效日期" prop="expirationDate">
          <el-date-picker  clearable size="small"
           :disabled="delFlag"
            v-model="form.expirationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择发布失效日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="商品图" prop="goodsPic">
        <div class="block" v-for="item in form.goodsPicArray" :key="item">
            <el-image
           disabled
              style="width: 100px; height: 100px"
              :src="item"
              fit="fill"
            ></el-image>
          </div>
        </el-form-item>
        <el-form-item label="发布商" prop="expirationName">

          <el-input :disabled="delFlag" v-model="form.expirationName" placeholder="请输入发布商" />
        </el-form-item>
        <el-form-item label="审核状态" prop="state">
           <el-select :disabled="delFlag" v-model="form.state" placeholder="请选择审核状态">
          <el-option
            v-for="item in authState"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          >
          </el-option>
        </el-select>
        </el-form-item>
      
        <el-form-item label="备注" prop="remark">
          <el-input :disabled="delFlag" v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
     <el-form-item label="是否通过审核" v-if='isHandle'>
          <el-radio-group v-model="examine" >
            <el-radio label="0">是</el-radio>
            <el-radio label="1">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="未通过审核原因" prop="reason" v-if='isHandle&&examine==="1"'>
          <el-input v-model="form.reason" placeholder="请输入未通过审核原因" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if='isHandle' @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listIntFoodMachinery, getIntFoodMachinery, delIntFoodMachinery, addIntFoodMachinery, updateIntFoodMachinery } from "@/api/indusInternet/foodMachinery";
import { listData } from "@/api/system/dict/data";

export default {
  name: "IntFoodMachinery",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 食品机械表格数据
      intFoodMachineryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        bigCategory: null,
        smallCategory: null,
        variety: null,
        producingArea: null,
        tradableTotal: null,
        unitPrice: null,
        yearDate: null,
        linkMan: null,
        phone: null,
        expirationDate: null,
        goodsPicId: null,
        expirationUserId: null,
        state: null,
        reason: null,
      },
      // 表单参数
      form: {},
      authState:[],
      examine: "0",
      delFlag: false,
      isHandle: false, //审核
      // 表单校验
      rules: {
        reason: [
          {
            required: true,
            message: "请输入未通过原因",
            trigger: "blur",
          },
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询互联网用户列表 */
    getdictDataList() {
      listData({ dictType: "publish_state" }).then((response) => {
        this.authState = response.rows;
      });
      
     
    },
    /** 查询食品机械列表 */
   async getList() {
      this.loading = true;
      await this.getdictDataList()
      listIntFoodMachinery(this.queryParams).then(response => {
         response.rows.forEach((item) => {
          item.goodsPicArray = item.goodsPicArray[0];

          this.authState.forEach((itemType) => {
            if (itemType.dictValue === item.state) {
              item.stateNew = itemType.dictLabel;
            }
          });
        });
        this.intFoodMachineryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        bigCategory: null,
        smallCategory: null,
        variety: null,
        producingArea: null,
        tradableTotal: null,
        unitPrice: null,
        yearDate: null,
        linkMan: null,
        phone: null,
        expirationDate: null,
        goodsPicId: null,
        expirationUserId: null,
        state: null,
        reason: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加食品机械";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      this.delFlag = true;
      this.isHandle = false;
      getIntFoodMachinery(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "食品机械查看";
      });
    },
     handle(row) {
      this.reset();
      const id = row.id || this.ids
      this.delFlag = true;
      this.isHandle = true;
      getIntFoodMachinery(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "食品机械审核";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
             if (this.examine === "0") {
            this.form.state = "2";
          } else {
            this.form.state = "5";
          }
            updateIntFoodMachinery(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
         
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除食品机械编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delIntFoodMachinery(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('internet/intFoodMachinery/export', {
        ...this.queryParams
      }, `internet_intFoodMachinery.xlsx`)
    }
  }
};
</script>